/**
 * Copyright (c) 2005-2012 https://github.com/zhangkaitao
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 */
package com.fast.commons.web.model;

import org.springframework.stereotype.Component;

/**
 * <p>User: Zhang Kaitao
 * <p>Date: 13-2-8 上午11:10
 * <p>Version: 1.0
 */
@Component
public class AjaxResponse {
    private Boolean status;
    private String message;
    private Object obj ;

    
    public AjaxResponse() {
        this(Boolean.TRUE, "操作成功");
    }

    public AjaxResponse(Boolean success) {
        this(success, null);
    }

    public AjaxResponse(String message) {
        this(Boolean.TRUE, "操作成功");
    }
    
    public AjaxResponse reset() {
    	this.status = Boolean.TRUE;
    	this.message = "操作成功";
    	this.obj = null ;
    	return this ;
    }
    
    
    public AjaxResponse(Boolean status, String message) {
    	this.status = status;
    	this.message = message;
    	if (this.message == null) {
    		if (Boolean.FALSE.equals(status)) {
    			this.message = "操作失败";
    		}
    		if (Boolean.TRUE.equals(status)) {
    			this.message = "操作成功";
    		}
    	}
    }

    public AjaxResponse(Boolean status, String message, Object obj) {
        this.status = status;
        this.message = message;
        this.obj = obj ;
        if (this.message == null) {
            if (Boolean.FALSE.equals(status)) {
                this.message = "操作失败";
            }
            if (Boolean.TRUE.equals(status)) {
                this.message = "操作成功";
            }
        }
    }


    public Object getObj() {
		return obj;
	}

	public void setObj(Object obj) {
		this.obj = obj;
	}

	public AjaxResponse fail() {
		return fail(null);
	}
	
	public AjaxResponse fail(String message) {
		return new AjaxResponse(Boolean.FALSE, message);
	}
	
	public static AjaxResponse failMsg() {
        return failMsg(null);
    }

    public static AjaxResponse failMsg(String message) {
        return new AjaxResponse(Boolean.FALSE, message);
    }

    public static AjaxResponse success() {
        return success(null);
    }

    public static AjaxResponse success(String message) {
        return new AjaxResponse(Boolean.TRUE, message);
    }


    public Boolean getStatus() {
		return status;
	}

	public void setStatus(Boolean status) {
		this.status = status;
	}

	public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}
